package hotel.quartz.oversea.job.meituan;

import com.alibaba.fastjson.JSON;
import hotel.base.oversea.constant.CommonConstants;
import hotel.base.oversea.constant.CommonUrlConstants;
import hotel.base.oversea.constant.quartz.UrlSwitchsEnums;
import hotel.base.oversea.utils.DateUtil;
import hotel.base.oversea.utils.Result;
import hotel.quartz.oversea.job.base.BaseJob;
import hotel.quartz.oversea.util.JobRestTemplateUtils;
import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;
import org.quartz.JobExecutionContext;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.client.RestTemplate;

import java.util.HashMap;
import java.util.Map;

/**
 * <p>
 *  每天新增一张日期表
 * </p>
 *
 * @description: Create Day Table About Goods Info Job
 * @author: qiuyy
 * @date: 2020-05-26 13:22
 * @version: V1.0
 */
@Slf4j
public class CreateDayTableAboutGoodsInfoJob implements BaseJob {
    private String timestamp = "Cdtagij"+String.valueOf(System.currentTimeMillis());

    @Autowired
    private RestTemplate restTemplate;


    @Override
    @SneakyThrows
    public void execute(JobExecutionContext jobExecutionContext) {

        log.info("Create Day Table About Goods Info Job {} >>>>>>>> 创建美团价格异步通知日期表 执行时间: {}", timestamp, DateUtil.getCurrTime());

        request();

        log.info("Create Day Table About Goods Info Job {} >>>>>>>> 创建美团价格异步通知日期表 结束时间: {},{}",timestamp, DateUtil.getCurrTime());

    }

    private void request() {
        String callbackHost = CommonUrlConstants.CALLBACK_HOST;
        String url = callbackHost+ UrlSwitchsEnums.sql.CREATE_TABLE.getValue();
        log.info("Create Day Table About Goods Info Job {} 创建美团价格异步通知日期表 进入方法 request",timestamp);
        //发起请求
        Map params = new HashMap();
        Result response = JobRestTemplateUtils.post(url, JSON.toJSONString(params),restTemplate);
        if(response.getCode()== CommonConstants.SUCCESS){
        }else{
            log.error("Create Day Table About Goods Info Job {} 创建美团价格异步通知日期表进入方法 request 返回失败：{},{}",timestamp, JSON.toJSONString(response), JSON.toJSONString(params));
        }
        //携程创建记录价格房态日志表 2021-03-24
        String switchOnlineHost = CommonUrlConstants.SWITCHS_ONLINE_HOST;
        url = switchOnlineHost+ UrlSwitchsEnums.sql.CREATE_SWITCH_TABLE.getValue();
        log.info("Create Day Table About switch price and check Job {} 创建携程效验价格房态日期表 进入方法 request",timestamp);
        response = JobRestTemplateUtils.get(url,params,restTemplate);
        if(response.getCode()== CommonConstants.SUCCESS){
        }else{
            log.error("Create Day Table About switch price and check Job {} 创建携程效验价格房态日期表 request 返回失败：{},{}",timestamp, JSON.toJSONString(response), JSON.toJSONString(params));
        }
    }
}
